#pragma once

//#define USE_CRITICAL_SECTION 1

struct Node{
	int data;
	Node* next;
};

struct Stack {
	Node* head;
	#ifdef USE_CRITICAL_SECTION
	CRITICAL_SECTION critical_sec
	#endif
};

void Push (Stack *stk, Node *newNode) {
	#ifdef USE_CRITICAL_SECTION
	//enter critical section, add a new node and then
	//leave critical section
	EnterCriticalSection (&stk->critical_sec); 
	#endif

	newNode->next = stk->head;
	stk->head = newNode;

	#ifdef USE_CRITICAL_SECTION
	LeaveCriticalSection (&stk->critical_sec); 
	#endif
}

Node* Pop(Stack *stk) {
#ifdef USE_CRITICAL_SECTION
	//enter critical section, add a new node and then
	//leave critical section
	EnterCriticalSection (&stk->critical_sec); 
#endif
	Node* temp = stk->head;
	stk->head = stk->head->next;
#ifdef USE_CRITICAL_SECTION
	LeaveCriticalSection (&stk->critical_sec); 
#endif
	return temp;
}

